/*
 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

enum class EntrypointId : uint32_t {
% Compiler::entrypoints.each_with_index do |entrypoint, index|
    <%= entrypoint.enum_name %> = <%= index %>,
% end
    COUNT,
    INVALID = COUNT
};

// NOLINTNEXTLINE(readability-function-size)
constexpr const char* GetEntrypointName(EntrypointId id) {
    ASSERT(id < EntrypointId::COUNT);
    // NOLINTNEXTLINE(modernize-avoid-c-arrays)
    constexpr const char* NAMES[static_cast<size_t>(EntrypointId::COUNT)] = {
% Compiler::entrypoints.each do |entrypoint|
        "<%= entrypoint.name %>",
% end
    };
    return NAMES[static_cast<size_t>(id)];
}

// NOLINTNEXTLINE(readability-function-size)
bool IsEntrypointNoreturn(EntrypointId id) {
    ASSERT(id < EntrypointId::COUNT);
    switch(id) {
% Compiler::entrypoints.each do |entrypoint|
        case EntrypointId::<%= entrypoint.enum_name %>:
            return <%= entrypoint.has_property? 'no_return' %>;
% end
        case EntrypointId::COUNT:
            UNREACHABLE();
    }
    UNREACHABLE();
}

// NOLINTNEXTLINE(readability-function-size)
size_t GetEntrypointArgsNum(EntrypointId id) {
    ASSERT(id < EntrypointId::COUNT);
    switch(id) {
% Compiler::entrypoints.each do |entrypoint|
        case EntrypointId::<%= entrypoint.enum_name %>:
            return <%= entrypoint.signature.length - 1 %>;
% end
        case EntrypointId::COUNT:
            UNREACHABLE();
    }
    UNREACHABLE();
}

bool IsEntrypointFastPath(EntrypointId id) {
    ASSERT(id < EntrypointId::COUNT);
    switch (id) {
% Compiler::entrypoints.select { |e| e.has_property? 'irtoc' }.each do |entrypoint|
    case EntrypointId::<%= entrypoint.enum_name %>:
% end
    return true;
default:
    return false;
    }
}
